package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Doctor;
import com.ruoyi.web.service.IDoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 医生
 * </p>
 */
@RestController
@RequestMapping("/database/doctor")
public class DoctorController extends BaseController {

    @Autowired
    private IDoctorService doctorService;

    /**
     * 查询医生列表列表
     */
    @PreAuthorize("@ss.hasPermi('database:doctor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Doctor doctor)
    {
        startPage();
        List<Doctor> list = doctorService.selectDoctorList(doctor);
        return getDataTable(list);
    }

    /**
     * 获取医生列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('database:doctor:query')")
    @GetMapping(value = "/{doctorid}")
    public AjaxResult getInfo(@PathVariable("doctorid") Long doctorid)
    {
        return success(doctorService.selectDoctorByDoctorid(doctorid));
    }

    /**
     * 新增医生列表
     */
    @PreAuthorize("@ss.hasPermi('database:doctor:add')")
    @Log(title = "医生列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Doctor doctor)
    {
        return toAjax(doctorService.insertDoctor(doctor));
    }

    /**
     * 修改医生列表
     */
    @PreAuthorize("@ss.hasPermi('database:doctor:edit')")
    @Log(title = "医生列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Doctor doctor)
    {
        return toAjax(doctorService.updateDoctor(doctor));
    }

    /**
     * 删除医生列表
     */
    @PreAuthorize("@ss.hasPermi('database:doctor:remove')")
    @Log(title = "医生列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{doctorids}")
    public AjaxResult remove(@PathVariable Long[] doctorids)
    {
        return toAjax(doctorService.deleteDoctorByDoctorids(doctorids));
    }
}
